﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace wUniAppPCL.IO
{


  public class wSerializer<TResult, TSerializer> where TResult : new() where TSerializer : IwSerializer<TResult>, new()
  {
    public wSerializer()
    {
      serializer = new TSerializer();
    }

    private TSerializer serializer;

    public TResult Deserialize(Stream srcStream)
    {
      var res = new TResult(); // default(TResult);
      try
      {
        return (TResult) serializer.Deserialize(srcStream);
      }
      catch (Exception ex)
      {
        wLogger.ToLog(ex);
        return res;
      }
    }
    public Exception Serialize(Stream dstStream, TResult source)
    {
      Exception res = null;
      try
      {
        serializer.Serialize(dstStream, source);
        return res;
      }
      catch (Exception ex)
      {
        wLogger.ToLog(ex);
        return ex;
      }
    }

  }

  
}
